﻿@model MessageTemplateListModel

@{
    //page title
    ViewBag.Title = T("Admin.ContentManagement.MessageTemplates").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Message templates");
}

@Html.AntiForgeryToken()
<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.ContentManagement.MessageTemplates")
    </h1>
    <div class="pull-right">
        &nbsp;
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            @if (!Model.AvailableProjects.SelectionIsNotPossible())
            {
                <div class="panel panel-default panel-search">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <div class="col-md-4">
                                        @Html.SDFLabelFor(model => model.SearchProjectId)
                                    </div>
                                    <div class="col-md-8">
                                        @Html.SDFDropDownList("SearchProjectId", Model.AvailableProjects)
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-md-8 col-md-offset-4">
                                        <button type="button" id="search-templates" class="btn btn-primary btn-search">
                                            <i class="fa fa-search"></i>
                                            @T("Admin.Common.Search")
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            }

            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="templates-grid"></div>

                    <script>
                        $(document).ready(function() {
                            $("#templates-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("List", "MessageTemplate"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: additionalData
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    numeric: false,
                                    previousNext: false,
                                    info: false
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                columns: [
                                    {
                                        field: "Name",
                                        title: "@T("Admin.ContentManagement.MessageTemplates.Fields.Name")"
                                    }, {
                                        field: "Subject",
                                        title: "@T("Admin.ContentManagement.MessageTemplates.Fields.Subject")"
                                    }, {
                                        field: "IsActive",
                                        title: "@T("Admin.ContentManagement.MessageTemplates.Fields.IsActive")",
                                        width: 100,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '# if(IsActive) {# <i class="fa fa-check true-icon"></i> #} else {# <i class="fa fa-close false-icon"></i> #} #'
                                    }, {
                                        field: "ListOfProjects",
                                        title: "@T("Admin.ContentManagement.MessageTemplates.Fields.LimitedToProjects")",
                                        width: 300
                                    }, {
                                        field: "Id",
                                        title: "@T("Admin.Common.Edit")",
                                        width: 100,
                                        template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>'
                                    }
                                ]
                            });
                        });
                    </script>

                    <script type="text/javascript">
                        $(document).ready(function() {
                            //search button
                            $('#search-templates').click(function() {
                                //search
                                var grid = $('#templates-grid').data('kendoGrid');
                                grid.dataSource.read();
                            });
                        });

                        function additionalData() {
                            var data = {
                                SearchProjectId: $('#SearchProjectId').val()
                            };
                            addAntiForgeryToken(data);
                            return data;
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>